| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | const assert = require('assert'); |
||
| 11 | describe('GeezifyTest', () => { |
||
| 12 | describe('#test_random_numbers()', () => { |
||
| 13 | it('should convert random ascii number to geez and back to the original', () => { |
||
| 14 | const $geezify = Geezify.create(); |
||
| 15 | |||
| 16 | for (let $i = 0; $i < 10000; $i += 1) { |
||
| 17 | const $random_number = Math.floor(Math.random() * 9999999999); |
||
| 18 | |||
| 19 | const $geez_number = $geezify.toGeez($random_number); |
||
| 20 | const $ascii_number = $geezify.toAscii($geez_number); |
||
| 21 | |||
| 22 | assert.equal($random_number, $ascii_number); |
||
| 23 | } |
||
| 24 | }); |
||
| 25 | }); |
||
| 26 | |||
| 27 | describe('#test_geezify_build_process()', () => { |
||
| 28 | it('should use provided ascii and geez number converters', () => { |
||
| 29 | const $geez = new GeezConverter(); |
||
| 30 | const $ascii = new AsciiConverter(); |
||
| 31 | |||
| 32 | sinon |
||
| 33 | .stub($geez, 'convert') |
||
| 34 | .withArgs(123) |
||
| 35 | .returns('giber gaber'); |
||
| 36 | sinon |
||
| 37 | .stub($ascii, 'convert') |
||
| 38 | .withArgs('lorem ipsum') |
||
| 39 | .returns(321); |
||
| 40 | |||
| 41 | const $geezify = new Geezify($geez, $ascii); |
||
| 42 | |||
| 43 | // assert the response |
||
| 44 | assert.equal(321, $geezify.toAscii('lorem ipsum')); |
||
| 45 | assert.equal('giber gaber', $geezify.toGeez(123)); |
||
| 46 | }); |
||
| 47 | }); |
||
| 48 | |||
| 49 | describe('#test_setter_and_getters()', () => { |
||
| 50 | it('should be able to substitute implementations', () => { |
||
| 51 | const $geezify = Geezify.create(); |
||
| 52 | |||
| 53 | const $geez_dummy = sinon.createStubInstance(GeezConverter); |
||
| 54 | const $ascii_dummy = sinon.createStubInstance(AsciiConverter); |
||
| 55 | |||
| 56 | $geezify.setGeezConverter($geez_dummy); |
||
| 57 | $geezify.setAsciiConverter($ascii_dummy); |
||
| 58 | |||
| 59 | assert.equal($geez_dummy, $geezify.getGeezConverter()); |
||
| 60 | assert.equal($ascii_dummy, $geezify.getAsciiConverter()); |
||
| 61 | }); |
||
| 62 | }); |
||
| 63 | }); |
||
| 64 |